package leetcode.ArrayAndString;

public class FindMaxConsecutiveOnes {
    /**
     * 给定一个二进制数组， 计算其中最大连续1的个数。
     */

    public static int findMaxConsecutiveOnes(int[] nums) {
        int result = 0;
        if (nums.length == 0) {
            return result;
        }
        int i = 0;
        for (int num : nums) {
            if (num == 1) {
                i++;
            } else {

                i = 0;
            }
            if(i>result){
                result=i;
            }
        }
        return result;


    }


    public static void main(String[] args) {
        int[] nums1 = {1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1};
        int[] nums2 = {};
        int[] nums3 = {1};
        int[] nums4 = {0};
        int[] nums5 = {1,0,1,1,0,1};

        System.out.println(findMaxConsecutiveOnes(nums5));

    }
}
